﻿using System;
using System.Collections.Generic;

using WebDavProcessor.Constants;

namespace WebDavProcessor.Resources
{
    public class WebDavResourceProperties : WebDavResource
    {
        private List<WebDavProperty> resourceProperties;

        public List<WebDavProperty> Properties { get { return resourceProperties; } }

        public object CreationDate { get { return this.FindProperty(WebDavPropertyNames.CreationDate); } }
        public object DisplayName { get { return this.FindProperty(WebDavPropertyNames.DisplayName); } }
        public object LockDiscovery { get { return this.FindProperty(WebDavPropertyNames.LockDiscovery); } }
        public object ResourceType { get { return this.FindProperty(WebDavPropertyNames.ResourceType); } }
        public object SupportedLock { get { return this.FindProperty(WebDavPropertyNames.SupportedLock); } }

        public WebDavResourceProperties(string path, int status)
            : base(path, status)
        {
            resourceProperties = new List<WebDavProperty>();
        }
        public WebDavResourceProperties(string path)
            : base(path)
        {
            resourceProperties = new List<WebDavProperty>();
        }

        public object FindProperty(string name)
        {
            foreach (WebDavProperty prop in this.Properties)
            {
                if (prop.Name == name)
                {
                    return prop.Value;
                }
            }
            return null;
        }
    }
}
